<?php

namespace Acme\TestBundle\Controller;

use Acme\TestBundle\Entity\Course;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

/**
 * Class CourseController
 * @Route("/course")
 */
class CourseController extends Controller
{
    /**
     * @Route("/create")
     */
    public function createAction(){
        $course = new Course();
        $course->setTid(3);
        $course->setName('英语');

        $em = $this->getDoctrine()->getManager();

        $em->persist($course);

        $em->flush();
        var_dump($course->getId());die();
    }

    /**
     * @Route("/get")
     */
    public function getAction(){
        $em = $this->getDoctrine()->getManager();
        $query = $em->createQuery(
            'select a from AcmeTestBundle:Course a where a.id=:id'
        )->setParameter('id',1);

        $course = $query->getResult();


        echo '<pre>';
        var_dump($course);
        echo '</pre>';die();
    }

    /**
     * @Route("/update")
     */
    public function updateAction(){
        $em = $this->getDoctrine()->getManager();
        $course = $em->getRepository('AcmeTestBundle:Course')->find(1);

        if(!$course){
            throw $this->createNotFoundException(
                'No cource found for id:1'
            );
        }
        $course->setName = '生物';
        $em->flush();

        var_dump($course);die();
    }


}
